package cn.anecansaitin.whimsy.client.enchantment;

import cn.anecansaitin.whimsy.Whimsy;
import cn.anecansaitin.whimsy.common.register.ModEnchantments;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.Mod;
import net.neoforged.neoforge.client.event.ComputeFovModifierEvent;

@Mod.EventBusSubscriber(modid = Whimsy.MODID, value = Dist.CLIENT)
public class EagleViewEvent {
    @SubscribeEvent
    public static void eagleView(ComputeFovModifierEvent event) {
        Player player = event.getPlayer();
        ItemStack item = player.getUseItem();

        if ((!item.is(Items.BOW) || item.getEnchantmentLevel(ModEnchantments.EAGLE_VIEW.get()) <= 0)) {
            return;
        }

        float f = event.getFovModifier();
        int i = player.getTicksUsingItem();
        float f1 = (float) i / 20.0F;

        if (f1 > 1.0F) {
            f1 = 1.0F;
        } else {
            f1 *= f1;
        }

        f /= 1.0F - f1 * 0.15F;
        event.setNewFovModifier(f);
    }
}
